其他
软件应用丨Seaborn简单画图:(一)
版权声明:本文为CSDN博主「向前走别回头」的原创文章合辑,遵循 CC 4.0 BY-SA 版权协议,特此附上原文出处链接及本声明。
原文链接:
https://blog.csdn.net/weixin_39778570/article/details/81145721
https://blog.csdn.net/weixin_39778570/article/details/81145868
散点图
import pandas as pd
import numpy as np
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
# 打开一个花瓣长宽数据文件
f = open('iris.csv')
iris = pd.read_csv(f)
iris.head()
SepalLength SepalWidth PetalLength PetalWidth Name
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa
# 绘制的颜色字典,zip传入俩个列表
iris.Name.unique()
array(['Iris-setosa', 'Iris-versicolor', 'Iris-virginica'], dtype=object)
color_map = dict(zip(iris.Name.unique(), ['blue','green','red']))
for species, group in iris.groupby('Name'):
plt.scatter(group['PetalLength'], group['SepalLength'],
color=color_map[species],
alpha=0.3,edgecolor=None,
label=species)
plt.legend(frameon=True, title='Name')
plt.xlabel('PetalLength')
plt.ylabel('SepalLength')
sns.lmplot('PetalLength','SepalLength',iris,hue='Name', fit_reg=False)
直方图和密度图
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pandas import Series, DataFrame
%matplotlib inline
import seaborn as sns
# 使用matplotlib
s1 = Series(np.random.randn(1000))
plt.hist(s1)
(array([ 6., 33., 98., 154., 230., 218., 163., 61., 29., 8.]),
array([-2.96113056, -2.35197999, -1.74282942, -1.13367884, -0.52452827,
0.08462231, 0.69377288, 1.30292346, 1.91207403, 2.52122461,
3.13037518]),
<a list of 10 Patch objects>)
![这里写图片描述](https://img-blog.csdn.net/20180721160403550?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zOTc3ODU3MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
s1.plot(kind='kde')
<matplotlib.axes._subplots.AxesSubplot at 0x277853b9a20>
Seaborn
# 同时绘制密度图和直方图
sns.distplot(s1, hist=True, kde=True)
<matplotlib.axes._subplots.AxesSubplot at 0x277853b9a20>
sns.distplot(s1, hist=True, kde=False, rug=True)
<matplotlib.axes._subplots.AxesSubplot at 0x277859199e8>
sns.distplot(s1, bins=20, hist=True, kde=False, rug=True, color='k')
# 绘制密度图的另一种方法,shada阴影填充
sns.kdeplot(s1, shade=True, color='r')
·END·
点击阅读原文,进入新型农业经营主体大数据库
终于等到你丨企研大数据资源预览系统上线啦!
点击登录丨新型农业经营主体大数据库展示平台正式上线啦!
数据Seminar
这里是大数据、分析技术与学术研究的三叉路口
出处:CSDN作者:向前走别回头推荐:青酱排版编辑:青酱
欢迎扫描👇二维码添加关注
点击阅读原文,获得更多精彩内容!